package cn.lingyangwl.agile.infra.weixin.mp.controller;

import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.framework.validation.group.UpdateGroup;
import cn.lingyangwl.agile.infra.weixin.mp.model.entity.MpUser;
import cn.lingyangwl.agile.infra.weixin.mp.model.rqrs.MpUserPageReq;
import cn.lingyangwl.agile.infra.weixin.mp.model.rqrs.MpUserResp;
import cn.lingyangwl.agile.infra.weixin.mp.model.rqrs.MpUserUpdateReq;
import cn.lingyangwl.agile.infra.weixin.mp.service.MpUserService;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 公众号粉丝
 * 
 * @author shenguangyang
 */
@Api(tags = "公众号粉丝")
@RestController
@RequestMapping("/mpUser")
public class MpUserController {
    @Resource
    private MpUserService mpUserService;
  
    /**
     * 分页 公众号粉丝
     */
    @RamResource(action = "weixin:mpUser:query", name = "查询公众号粉丝", type = ActionType.READ)
    @GetMapping("/pageMpUser")
    public Resp<IPage<MpUserResp>> pageUser(@Validated MpUserPageReq req) {
        return Resp.ok(mpUserService.pageUser(req));
    }
  
    /**
     * 通过id查找 公众号粉丝
     */
    @RamResource(action = "weixin:mpUser:query", name = "查询公众号粉丝", type = ActionType.READ)
    @GetMapping("/getMpUser")
    public Resp<MpUser> getUserById(@RequestParam(value = "id") Long id) {
        return Resp.ok(mpUserService.getUserById(id));
    }
  
    /**
     * 更新 公众号粉丝
     */
    @RamResource(action = "weixin:mpUser:update", name = "更新公众号粉丝", type = ActionType.WRITE)
    @PostMapping("/updateMpUser")
    public Resp<?> updateUserById(@Validated(UpdateGroup.class) @RequestBody MpUserUpdateReq rq) {
        return Resp.ok(mpUserService.updateUser(rq));
    }

    @PostMapping("/syncMpUser")
    @ApiOperation(value = "同步公众号粉丝")
    @RamResource(action = "weixin:mpUser:syncUser", name = "同步公众号粉丝", type = ActionType.WRITE)
    public Resp<Boolean> syncUser() {
        mpUserService.syncUser();
        return Resp.ok(true);
    }

}
